function Paginator(page, firstPage, previousPage, nextPage, lastPage, currentPage,  totalPages){
	
	this.page = page;
	
	this.firstPage = firstPage;
	this.previousPage = previousPage;
	this.nextPage = nextPage;
	this.lastPage = lastPage;
	this.currentPage = currentPage;
	this.totalPages = totalPages;
	
	
	this.onFirstPage = function(){};
	this.onPreviousPage = function(){};
	this.onNextPage = function(){};
	this.onLastPage = function(){};
	this.onPageChange = function(){};
	
	this.updatePageBookmarks();
	
	this.initEvents();
	
	return this;
}

// ------------------------------------------------------------------------------------------------

Paginator.prototype.initEvents = function(){
	var paginator = this;
	
	//Goto to first page
	XBrowserAddHandler(this.firstPage, "click", function onClick(){
		paginator.page.setCurrentPage(1);
		paginator.onFirstPage();
		paginator.onPageChange();
		paginator.updatePageBookmarks();
	});
	
	//Goto to previous page
	XBrowserAddHandler(this.previousPage, "click", function onClick(){
		if (paginator.page.getCurrentPage() > 1){
			paginator.page.setCurrentPage(paginator.page.getCurrentPage()-1);
		}
		
		paginator.onPreviousPage();
		paginator.onPageChange();		
		paginator.updatePageBookmarks();
	});
	
	//Goto to next page
	XBrowserAddHandler(this.nextPage, "click", function onClick(){
		if (paginator.page.getCurrentPage()<paginator.page.getPages()){
			
			paginator.page.setCurrentPage(paginator.page.getCurrentPage()+1);
		}
		
		paginator.onNextPage();
		paginator.onPageChange();
		paginator.updatePageBookmarks();
	});
	
	
	//Goto to last page
	XBrowserAddHandler(this.lastPage, "click",  function onClick(){
		paginator.page.setCurrentPage(paginator.page.getPages());
		
		paginator.onLastPage();
		paginator.onPageChange();
		paginator.updatePageBookmarks();		
	});

	XBrowserAddHandler(this.currentPage, "blur", function onClick(){
		if (paginator.currentPage.tagName.toLowerCase()=="input" && paginator.currentPage.type.toLowerCase()=="text"){
			var pageNumber = paginator.currentPage.value;
			if (!isNaN(pageNumber) && pageNumber > 0 && pageNumber<=paginator.page.getPages()){
				paginator.page.setCurrentPage(Number(pageNumber));
				paginator.onPageChange();
			}
		}
		
		
		paginator.onFirstPage();
		paginator.onPageChange();
		paginator.updatePageBookmarks();
	});
};

// ------------------------------------------------------------------------------------------------

Paginator.prototype.updatePageBookmarks = function(){
	//Update current page
	if (this.currentPage.tagName.toLowerCase()=="input" && this.currentPage.type.toLowerCase()=="text"){
		this.currentPage.value = this.page.getCurrentPage();
	}else{
		this.currentPage.innerHTML = this.page.getCurrentPage();
	}
	
	//Update total pages
	if (this.totalPages.tagName.toLowerCase()=="input" && this.totalPages.type.toLowerCase()=="text"){
		this.totalPages.value = this.page.getPages();
	}else{
		this.totalPages.innerHTML = this.page.getPages();
	}
	
};

// ------------------------------------------------------------------------------------------------

Paginator.prototype.setPage = function(page){
	this.page = page;
};

// ------------------------------------------------------------------------------------------------

Paginator.prototype.getCurrentPageNumber = function(){
	return this.page.getCurrentPage();
};

// ------------------------------------------------------------------------------------------------

Paginator.prototype.getPage = function(){
	return this.page;
};